home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 11, No. 10 (1990-10)(MindCraft Publishing)(Side A)[a].zip / Nibble Volume 11, No. 10 (1990-10)(MindCraft Publishing)(Side A)[a].po / TE.ASM.txt < prev    next >
Text File  |  1996-12-24  |  20KB  |  562 lines

  1. ****************************************
  2. *                                      *
  3. *  TE.ASM Source Listing (Data Fork)   *
  4. *          by  Sandy Mossberg          *
  5. *                                      *
  6. *         APW Assembler/Linker         *
  7. *  Requires APW Tools and Interfaces,  *
  8. *             version 1.1              *
  9. *                                      *
  10. *          Copyright (C) 1990          *
  11. *       by MindCraft Publ. Corp.       *
  12. *          Concord, MA  01742          *
  13. *                                      *
  14. ****************************************
  15.             mcopy    te.mac
  16.             keep     te.dfork
  17.  
  18. ScreenMode  gequ     $80             ;640x200 super hi-res mode
  19.  
  20. *****************************************************************
  21. *
  22. MainLoop    start
  23. *
  24. * Main program loop:
  25. *
  26. *****************************************************************
  27.             using    GlobalData
  28.  
  29.             phk                      ;equate program bank
  30.             plb                      ; with data bank
  31.             jsr      StartUp         ;startup tool sets
  32.             jsr      InitDesktop     ;initialize desktop
  33.             jsr      InitApplic      ;initialize application
  34.             jsr      EventLoop       ;scan for events
  35.             jsr      ShutApplic      ;free program memory
  36.             jsr      ShutDown        ;shutdown tool sets
  37. Quit        _QuitGS  QuitParm        ;quit to calling application
  38. ;................................................................
  39. ;
  40. ; MainLoop data:
  41. ;
  42. QuitParm    anop                     ;Quit parmlist (GS/OS class 1)
  43.             dc       i2'0'           ;pCount = 0 (input)
  44.             end
  45.  
  46. *****************************************************************
  47. *
  48. StartUp     start
  49. *
  50. * Startup tool sets:
  51. *
  52. *****************************************************************
  53.             using    GlobalData
  54.  
  55. ; Startup first 2 tool sets:
  56.  
  57.             _TLStartUp               ;----start Tool Locator
  58.  
  59.             pha                      ;space for result
  60.             _MMStartUp               ;----start Memory Manager
  61.             jsr      FatalErr
  62.             PullWord MasterID        ;save master ID
  63.  
  64. ; Startup other tool sets:
  65.  
  66.             PushLong #0              ;space for result
  67.             PushWord MasterID        ;master ID
  68.             PushWord #2              ;ref is resource
  69.             PushLong #$07FE0001      ;ref to orig StartStop record
  70.             _StartUpTools            ;----call StartUpTools
  71.             jsr      FatalErr
  72.             PullLong SSRecFinal      ;ref to final StartStop record
  73.  
  74.             _InitCursor              ;convert cursor: wait -> arrow
  75.             rts
  76.             end
  77.  
  78. *****************************************************************
  79. *
  80. ShutDown    start
  81. *
  82. * Shutdown tools sets:
  83. *
  84. *****************************************************************
  85.             using    GlobalData
  86.  
  87.             PushWord #1              ;reference is handle
  88.             PushLong SSRecFinal      ;ref to final StartStop record
  89.             _ShutDownTools           ;----call ShutDownTools
  90.  
  91.             PushWord MasterID        ;master ID
  92.             _MMShutDown
  93.             _TLShutDown
  94.             rts
  95.             end
  96.  
  97. *****************************************************************
  98. *
  99. FatalErr    start
  100. *
  101. * Check for error and handle fatal error:
  102. *
  103. *****************************************************************
  104.  
  105.             bcs      FE01            ;error detected
  106.             rts                      ;no error on carry clear
  107.  
  108. FE01        pha                      ;error code in A reg
  109.             PushLong #0              ;use default failure message
  110.             _SysFailMgr              ;die a horrible death
  111.             end
  112.  
  113. *****************************************************************
  114. *
  115. InitDesktop start
  116. *
  117. * Initialize desktop:
  118. *
  119. *****************************************************************
  120.  
  121.             PushLong #0            ;space for result
  122.             PushWord #2            ;reference is resource
  123.             PushLong #1            ;reference to menu bar
  124.             PushLong #0            ;system menu bar
  125.             _NewMenuBar2           ;create menu bar
  126.  
  127.             _SetSysBar             ;set system bar (handle on stack)
  128.  
  129.             PushLong #0            ;use system menu bar
  130.             _SetMenuBar            ;set current menu bar
  131.  
  132.             PushLong #0            ;entire desktop
  133.             _RefreshDesktop        ;refresh desktop
  134.  
  135.             PushWord #1            ;ID of NDA menu
  136.             _FixAppleMenu          ;setup NDA menu
  137.  
  138.             pha                    ;space for result
  139.             _FixMenuBar            ;set standard size of menu bar
  140.             pla                    ;discard menu height
  141.  
  142.             _DrawMenuBar           ;display current menu bar
  143.             rts
  144.             end
  145.  
  146. *****************************************************************
  147. *
  148. InitApplic  start
  149. *
  150. * Initialize application specific data:
  151. *
  152. *****************************************************************
  153.             using    GlobalData
  154.  
  155.             stz      QuitFlag        ;clear quit flag
  156.             stz      WindFlag        ;clear window flag
  157.             rts
  158.             end
  159.  
  160. *****************************************************************
  161. *
  162. EventLoop   start
  163. *
  164. * Handle events:
  165. *
  166. *****************************************************************
  167.             using    GlobalData
  168.  
  169.             jsr      ChangeMenus     ;dim/undim menu title/items
  170.  
  171.             anop                     ;scan events with TaskMaster
  172.             pha                      ;space for result
  173.             PushWord #$FFFF          ;handle all events
  174.             PushLong #TaskRecord     ;ptr to extended task record
  175.             _TaskMaster              ;get the event
  176.             pla                      ;get result
  177.  
  178.             anop                     ;handle event
  179.             asl      a               ;create index into 2-byte
  180.             tax                      ; entries of task table
  181.             jsr      (TaskTable,x)   ;call event handler
  182.  
  183.             anop                     ;check for quit signal
  184.             lda      QuitFlag
  185.             bpl      EventLoop       ;Quit not chosen
  186.             rts
  187. ;................................................................
  188. ;
  189. ; EventLoop data:
  190. ;
  191. TaskTable   anop                     ;GetNextEvent event handlers:
  192.             dc       i2'DoRTS'       ; 0 = nullEvt
  193.             dc       i2'DoRTS'       ; 1 = mouseDownEvt
  194.             dc       i2'DoRTS'       ; 2 = mouseUpEvt
  195.             dc       i2'DoRTS'       ; 3 = keyDownEvt
  196.             dc       i2'DoRTS'       ; 4 = undefined
  197.             dc       i2'DoRTS'       ; 5 = autoKeyEvt
  198.             dc       i2'DoRTS'       ; 6 = updateEvt
  199.             dc       i2'DoRTS'       ; 7 = undefined
  200.             dc       i2'DoRTS'       ; 8 = activateEvt
  201.             dc       i2'DoRTS'       ; 9 = switchEvt
  202.             dc       i2'DoRTS'       ;10 = deskAccEvt
  203.             dc       i2'DoRTS'       ;11 = driverEvt
  204.             dc       i2'DoRTS'       ;12 = app1Evt
  205.             dc       i2'DoRTS'       ;13 = app2Evt
  206.             dc       i2'DoRTS'       ;14 = app3Evt
  207.             dc       i2'DoRTS'       ;15 = app4Evt
  208.             anop                     ;TaskMaster event handlers:
  209.             dc       i2'DoRTS'       ;16 = wInDesktop
  210.             dc       i2'DoMenu'      ;17 = wInMenuBar
  211.             dc       i2'DoRTS'       ;18 = wClickCalled
  212.             dc       i2'DoRTS'       ;19 = wInContent
  213.             dc       i2'DoRTS'       ;20 = wInDrag
  214.             dc       i2'DoRTS'       ;21 = wInGrow
  215.             dc       i2'DoClose'     ;22 = wInGoAway
  216.             dc       i2'DoRTS'       ;23 = wInZoom
  217.             dc       i2'DoRTS'       ;24 = wInInfo
  218.             dc       i2'DoMenu'      ;25 = wInSpecial
  219.             dc       i2'DoRTS'       ;26 = wInDeskItem
  220.             dc       i2'DoRTS'       ;27 = wInFrame
  221.             dc       i2'DoRTS'       ;28 = wInactMenu
  222.             dc       i2'DoRTS'       ;29 = wClosedNDA
  223.             dc       i2'DoRTS'       ;30 = wCalledSysEdit
  224.             dc       i2'DoRTS'       ;31 = wTrackZoom
  225.             dc       i2'DoRTS'       ;32 = wHitFrame
  226.             dc       i2'DoRTS'       ;33 = wInControl
  227.             dc       i2'DoRTS'       ;34 = wInControlMenu
  228.             end
  229.  
  230. *****************************************************************
  231. *
  232. DoMenu      start
  233. *
  234. * Handle menu events (menu items must be numbered sequentially):
  235. *
  236. *****************************************************************
  237.             using    GlobalData
  238.  
  239.             sec
  240.             lda      TaskData        ;get menu item ID
  241.             sbc      #250            ;convert N250 into 0th item
  242.             asl      a               ;create index into 2-byte
  243.             tax                      ; entries of menu item table
  244.             jsr      (ItemTable,x)   ;call menu item handler
  245.  
  246.             PushWord #0              ;TRUE=hilite, FALSE=unhilite
  247.             PushWord TaskData+2      ;menu ID
  248.             _HiliteMenu              ;unhighlight menu
  249.             rts
  250. ;................................................................
  251. ;
  252. ; DoMenu data:
  253. ;
  254. ItemTable   anop                     ;menu item handlers
  255.             dc       i2'DoRTS'       ;250 = Undo
  256.             dc       i2'DoRTS'       ;251 = Cut
  257.             dc       i2'DoRTS'       ;252 = Copy
  258.             dc       i2'DoRTS'       ;253 = Paste
  259.             dc       i2'DoRTS'       ;254 = Clear
  260.             dc       i2'DoClose'     ;255 = Close
  261.             dc       i2'DoAbout'     ;256 = About...
  262.             dc       i2'DoQuit'      ;257 = Quit
  263.             dc       i2'DoNew'       ;258 = New
  264.             dc       i2'DoOpen'      ;259 = Open
  265.             dc       i2'DoRTS'       ;260 = Save...
  266.             dc       i2'DoRTS'       ;261 = Page Setup...
  267.             dc       i2'DoRTS'       ;262 = Print...
  268.             end
  269.  
  270. *****************************************************************
  271. *
  272. ShutApplic  start
  273. *
  274. * Deallocate memory before shutting down tool sets:
  275. *
  276. *****************************************************************
  277.             using    GlobalData
  278.  
  279.             rts
  280.             end
  281.  
  282. *****************************************************************
  283. *
  284. DoRTS       start
  285. *
  286. * Ignore an event:
  287. *
  288. *****************************************************************
  289.  
  290.             rts
  291.             end
  292.  
  293. *****************************************************************
  294. *
  295. DoQuit      start
  296. *
  297. * Turn on quit flag to terminate this application:
  298. *
  299. *****************************************************************
  300.             using    GlobalData
  301.  
  302.             lda      #$8000
  303.             sta      QuitFlag        ;set quit flag
  304.             rts
  305.             end
  306.  
  307. *****************************************************************
  308. *
  309. DoClose     start
  310. *
  311. * Close front window:
  312. *
  313. *****************************************************************
  314.             using    GlobalData
  315.  
  316.             PushLong #0              ;space for result
  317.             _FrontWindow             ;get ptr to front window
  318.             PullLong FrontWinPtr     ;save ptr
  319.  
  320.             lda      FrontWinPtr     ;check for open window
  321.             ora      FrontWinPtr+2
  322.             beq      Done            ;no window open
  323.  
  324.             PushLong FrontWinPtr     ;ptr to front window
  325.             _CloseNDAbyWinPtr        ;close NDA window
  326.             bcc      Done            ;NDA window closed
  327.  
  328.             anop                     ;application window in front
  329.             PushLong #0              ;get menu item ID in wRefCon
  330.             PushLong FrontWinPtr
  331.             _GetWRefCon
  332.             plx                      ;ID in lo
  333.             pla                      ;discard hi
  334.  
  335.             phx                      ;enable menu item
  336.             _EnableMItem
  337.  
  338.             PushLong FrontWinPtr     ;ptr to front window
  339.             _CloseWindow             ;close application window
  340.  
  341. Done        rts
  342.             end
  343.  
  344. *****************************************************************
  345. *
  346. DoAbout     start
  347. *
  348. * Handle About item in Apple menu (display title and credits):
  349. *
  350. *****************************************************************
  351.  
  352.             pha                      ;space for result
  353.             PushWord #5              ;ref is resource, P-string
  354.             PushLong #0              ;no substitution array
  355.             PushLong #$07FE0001      ;reference to alert string
  356.             _AlertWindow             ;display alert window
  357.             pla                      ;discard button ID (OK)
  358.             rts
  359.             end
  360.  
  361. *****************************************************************
  362. *
  363. DoNew       start
  364. *
  365. * Open new TextEdit window:
  366. *
  367. *****************************************************************
  368.             using    GlobalData
  369.  
  370.             PushLong #0              ;space for result
  371.             PushLong #0              ;ptr to replacement title
  372.             PushLong TaskData        ;repl refCon (New item ID)
  373.             PushLong #DrawNew        ;ptr to repl content drawing
  374.             PushLong #0              ;ptr to repl window  defProc
  375.             PushWord #2              ;ref is resource
  376.             PushLong #$1001          ;ref to window template
  377.             PushWord #$800E          ;type 1 (stnd) window template
  378.             _NewWindow2
  379.             jsr      LocalError      ;check nonfatal error
  380.             PullLong NewWindPtr      ;ptr to window GrafPort
  381.             bcs      Done            ;error
  382.  
  383.             PushWord TaskData        ;dim New item in File menu
  384.             _DisableMItem
  385. Done        rts
  386.             end
  387.  
  388. *****************************************************************
  389. *
  390. DoOpen      start
  391. *
  392. * Open preset TextEdit window:
  393. *
  394. *****************************************************************
  395.             using    GlobalData
  396.  
  397.             PushLong #0              ;space for result
  398.             PushLong #0              ;ptr to replacement title
  399.             PushLong TaskData        ;repl refCon (Open item ID)
  400.             PushLong #DrawOpen       ;ptr to repl content drawing
  401.             PushLong #0              ;ptr to repl window  defProc
  402.             PushWord #2              ;ref is resource
  403.             PushLong #$1101          ;ref to window template
  404.             PushWord #$800E          ;type 1 (stnd) window template
  405.             _NewWindow2
  406.             jsr      LocalError      ;check nonfatal error
  407.             PullLong OpenWindPtr     ;ptr to window GrafPort
  408.             bcs      Done            ;error
  409.  
  410.             PushWord TaskData        ;dim New item in File menu
  411.             _DisableMItem
  412. Done        rts
  413.             end
  414.  
  415. *****************************************************************
  416. *
  417. DrawNew     start
  418. *
  419. * Draw content region of New window (called by TaskMaster):
  420. *
  421. *****************************************************************
  422.             using    GlobalData
  423.  
  424.             PushLong NewWindPtr      ;ptr to New window
  425.             _DrawControls
  426.             rtl
  427.             end
  428.  
  429. *****************************************************************
  430. *
  431. DrawOpen    start
  432. *
  433. * Draw content region of Open window (called by TaskMaster):
  434. *
  435. *****************************************************************
  436.             using    GlobalData
  437.  
  438.             PushLong OpenWindPtr     ;ptr to New window
  439.             _DrawControls
  440.             rtl
  441.             end
  442.  
  443. *****************************************************************
  444. *
  445. ChangeMenus start
  446. *
  447. * Enable or disable menu titles and items during null events:
  448. *
  449. *****************************************************************
  450.             using    GlobalData
  451.  
  452.             PushLong #0              ;space for result
  453.             _FrontWindow             ;get ptr to front window
  454.             PullLong FrontWinPtr     ;save ptr
  455.  
  456.             ldx      #$8000          ;assume open window
  457.             lda      FrontWinPtr     ;check for open window
  458.             ora      FrontWinPtr+2
  459.             bne      CheckFlag       ;open window found
  460.             ldx      #0              ;no open window
  461.  
  462. CheckFlag   cpx      WindFlag
  463.             bne      ChangeFlag      ;flag changed
  464.             rts                      ;flag unchanged so exit
  465.  
  466. ChangeFlag  stx      WindFlag        ;set new flag
  467.  
  468.             lda      WindFlag        ;check for open window
  469.             bpl      NoWind          ;no window open
  470.  
  471.             anop                     ;window open so enable specials
  472.             PushWord #250            ;Undo
  473.             _EnableMItem
  474.  
  475.             PushWord #251            ;Cut
  476.             _EnableMItem
  477.  
  478.             PushWord #252            ;Copy
  479.             _EnableMItem
  480.  
  481.             PushWord #253            ;Paste
  482.             _EnableMItem
  483.  
  484.             PushWord #254            ;Clear
  485.             _EnableMItem
  486.  
  487.             PushWord #255            ;Close
  488.             _EnableMItem
  489.  
  490.             PushWord #$FF7F          ;flags: enable menu
  491.             PushWord #3              ;Edit menu number
  492.             _SetMenuFlag             ;enable Edit menu title
  493.             bra      Done
  494.  
  495. NoWind      anop                     ;no window open so dim specials
  496.             PushWord #255            ;Close
  497.             _DisableMItem
  498.  
  499.             PushWord #$80            ;flags: diaable menu
  500.             PushWord #3              ;Edit menu number
  501.             _SetMenuFlag             ;dim Edit menu title and items
  502.  
  503. Done        _DrawMenuBar             ;display current menu bar
  504.             rts
  505.             end
  506.  
  507. ****************************************************************
  508. *
  509. LocalError  start
  510. *
  511. * Handle nonfatal errors: entry A = error code
  512. *
  513. ****************************************************************
  514.             using    GlobalData
  515.  
  516.             bcc      Done            ;no error
  517.             tax                      ;save error code
  518.  
  519.             pha                      ;space for result
  520.             PushWord #0              ;type of substitution string
  521.             PushLong #0              ;ptr to substitution string
  522.             phx                      ;error code
  523.             _ErrorWindow             ;display error window
  524.             pla                      ;discard button number
  525.  
  526.             sec                      ;return with error signal
  527. Done        rts
  528.             end
  529.  
  530. *****************************************************************
  531. *
  532. GlobalData  data
  533. *
  534. * Global program data:
  535. *
  536. *****************************************************************
  537.  
  538. MasterID    ds       2           ;our master memory ID
  539. SSRecFinal  ds       4           ;ptr to final StartStop record
  540. FrontWinPtr ds       4           ;ptr to front window in Close item
  541. NewWindPtr  ds       4           ;ptr to New window GrafPort
  542. OpenWindPtr ds       4           ;ptr to Open window GrafPort
  543. QuitFlag    ds       2           ;quit=MI, no quit=PL
  544. WindFlag    ds       2           ;open window=MI, no window=PL
  545.  
  546. TaskRecord  anop                 ;new extended task record
  547. What        ds       2           ;event code
  548. Message     ds       4           ;event message
  549. When        ds       4           ;ticks since startup
  550. Where       ds       4           ;global position of mouse
  551. Modifiers   ds       2           ;state of modifier keys
  552. TaskData    ds       4           ;extended event data
  553. TaskMask    dc       i4'$1FFFFF' ;bit flag (handle all events)
  554. LastClkTick ds       4           ;tick value at last click
  555. ClickCount  ds       2           ;type of last click
  556. TaskData2   ds       4           ;additional data
  557. TaskData3   ds       4           ;additional data
  558. TaskData4   ds       4           ;additional data
  559. LastClickY  ds       2           ;vertical axis of last click
  560. LastClickX  ds       2           ;horizontal axis of last click
  561.             end
  562.